const express = require('express')
const router = express.Router()
const { addFootprint, getFootprint } = require('../../model/mongo')

router.post('/add', async (req, res) => {
    const { userid, proid } = req.body
    const result = {
        code: 200,
        msg: '添加足迹'
    }
    if (!userid.length || !userid) {
        result.msg = '请登录'
        res.send(JSON.stringify(result))
        return
    }

    result.data = await addFootprint(userid, proid)
    res.send(JSON.stringify(result))
})

router.get('/list', async (req, res) => {
    let { userid, timeStamp } = req.query
    const result = {
        code: 200,
        msg: '按照日期筛选足迹'
    }
    const date = new Date(Number(timeStamp))
    result.data = await getFootprint(userid, Number(timeStamp))
    res.send(JSON.stringify(result))
})

module.exports = router
